﻿using LiteBlog.Common.Entities;
using LiteBlog.Components.Contracts;
using LiteBlog.Controllers.Contracts;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LiteBlog.Controllers.Tests
{
    [TestClass]
    public class CategoryControllerTests : CompControllerTests<Category, string, ICategoryComp, ICategoryController>
    {
        [TestMethod]
        public void ReorderGetsCategory()
        {
            var list = new List<string>() { "1", "2", "3" };
            string order = string.Join(",", list.ToArray());
            var mock = Mock.Get<ICategoryComp>(_controller.GetComponent<ICategoryComp>());
            mock.Setup(c => c.Get(It.IsAny<string>())).Returns(new Category());
            _controller.Reorder(order);
            mock.Verify(c=>c.Get(It.Is<string>(
                (id) => list.Contains(id)
                )), Times.Exactly(3));
        }

        [TestMethod]
        public void ReorderUpdatesCategory()
        {
            var list = new List<string>() { "1", "2", "3" };
            string order = string.Join("," , list.ToArray());
            var mock = Mock.Get<ICategoryComp>(_controller.GetComponent<ICategoryComp>());
            mock.Setup<Category>(c => c.Get(It.IsAny<string>())).Returns<string>((id) => new Category { CatID = id});
            _controller.Reorder(order);
            mock.Verify(c => c.Update(It.Is<string>(
                (id) => list.Contains(id)
                ), It.Is<Category>((cat)=> list.Contains(cat.CatID))), Times.Exactly(3));
        }
    }
}
